LiveUser_Admin
[ class tree: LiveUser_Admin ] [ index: LiveUser_Admin ] [ all elements ]

Source for file GroupRights.php

Documentation is available at GroupRights.php

  1. <?php require_once 'index.php'?>
  2. <h3>GroupRights</h3>
  3. <?php
  4. $groups $admin->perm->getGroups();
  5. if  (empty($groups)) {
  6.     echo 'Run the <b>Group</b> test first<br />';
  7.     exit;
  8. }
  9.  
  10. $rights $admin->perm->getRights();
  11. if  (empty($rights)) {
  12.     echo 'Run the <b>Right</b> test first<br />';
  13.     exit;
  14. }
  15.  
  16.  
  17. for ($i = 0; $i < 20; $i++{
  18.     $right   array_rand($rights);
  19.     $group array_rand($groups);
  20.     $data = array(
  21.         'group_id' => $groups[$group]['group_id'],
  22.         'right_id' => $rights[$right]['right_id']
  23.     );
  24.     $granted $admin->perm->grantGroupRight($data);
  25.  
  26.     if ($granted === false{
  27.         echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  28.     else {
  29.         echo 'Group <b>' $group '</b> was granted the right <b>'.$right.'</b><br />';
  30.     }
  31.     unset($rights[$right]);
  32.     $rights array_values($rights);
  33. }
  34.  
  35. $group array_rand($groups);
  36. $params = array(
  37.     'fields' => array(
  38.         'right_id',
  39.         'right_define_name',
  40.     ),
  41.     'with' => array(
  42.         'group_id' => array(
  43.             'fields' => array(
  44.                 'group_id',
  45.             ),
  46.         ),
  47.     ),
  48.     'filters' => array(
  49.         'group_id' => $groups[$group]['group_id']
  50.     ),
  51.     'limit' => 10,
  52.     'offset' => 0,
  53. );
  54. $allGroupRights $admin->perm->getRights($params);
  55.  
  56. if ($allGroupRights === false{
  57.     echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  58. else {
  59.     echo '<hr />Here is/are <b>' count($allGroupRights'</b> group right(s) for the group <b>' $groups[$group]['group_id''</b>:<br />';
  60.     Var_Dump::display($allGroupRights);
  61.     echo '<br />';
  62. }
  63.  
  64. $right   array_rand($rights);
  65. $group array_rand($groups);
  66. $filters = array(
  67.     'right_id' => $rights[$right]['right_id'],
  68.     'group_id' => $groups[$group]['group_id']
  69. );
  70. $removed $admin->perm->revokeGroupRight($filters);
  71.  
  72. if ($removed === false{
  73.     echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  74. else {
  75.     echo 'Removed the right <b>'.$right.'</b> on group <b>'.$group.'</b><br />';
  76. }
  77.  
  78.  
  79. $group array_rand($groups);
  80. $params = array(
  81.     'fields' => array(
  82.         'right_id'
  83.     ),
  84.     'filters' => array(
  85.         'group_id' => $groups[$group]['group_id']
  86.     )
  87. );
  88. $rights_group $admin->perm->getRights($params);
  89. if ($rights_group === false{
  90.     echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  91. else {
  92.     $right   array_rand($rights_group);
  93.     $data = array('right_level' => 2);
  94.     $filters = array(
  95.         'right_id' => $rights_group[$right]['right_id'],
  96.         'group_id' => $groups[$group]['group_id']
  97.     );
  98.     $updated $admin->perm->updateGroupRight($data$filters);
  99.  
  100.     if ($updated === false{
  101.         echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  102.     else {
  103.         echo 'Updated the right level of <b>' $groups[$group]['group_id''</b><br />';
  104.         $params = array(
  105.             'fields' => array(
  106.                 'right_id'
  107.             ),
  108.             'filters' => array(
  109.                 'right_id' => $rights_group[$right]['right_id'],
  110.                 'group_id' => $groups[$group]['group_id']
  111.             )
  112.         );
  113.         $result $admin->perm->getRights($params);
  114.  
  115.         if ($result === false{
  116.             echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  117.         else {
  118.             Var_Dump::display($result);
  119.         }
  120.     }
  121. }
  122.  
  123. $params = array(
  124.     'fields' => array(
  125.         'right_id',
  126.     ),
  127.     'with' => array(
  128.         'group_id' => array(
  129.             'fields' => array(
  130.                 'group_id',
  131.                 'right_level',
  132.             )
  133.         ),
  134.     ),
  135. );
  136.  
  137. $allGroups $admin->perm->getRights($params);
  138. echo 'Here are all the group rights after the changes:<br />';
  139. if ($allGroups === false{
  140.     echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  141. else {
  142.     Var_Dump::display($allGroups);
  143. }
  144. echo '<hr />';

Documentation generated on Mon, 11 Mar 2019 14:00:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.